/*
 * test.cpp
 *
 *  Created on: May 29, 2011
 *      Author: gilang
 */

#include "SinglePoint.h"
#include "Node.h"
#include "LineElement.h"
#include "TriangularElement.h"
#include "Mesh.h"
#include <iostream>
#include <iomanip>

using namespace std;

typedef Matrix<double> matrix;
typedef Vector<double> vect;

int main() {

	LineElement el;
	el.setLabel("element 1");
	el.setMaterial(Material(21, 0, 0));
	el.addNode(0, Node(0.0));
	el.addNode(1, Node(0.0075));

	LineElement el2;
	el2.setLabel("element 2");
	el2.setMaterial(Material(21, 0, 0));
	el2.addNode(0, Node(el.get(1)));
	el2.addNode(1, Node(0.015));

	LineElement el3;
	el3.setLabel("element 3");
	el3.setMaterial(Material(21, 0, 0));
	el3.addNode(0, Node(el2.get(1)));
	el3.addNode(1, Node(0.0225));

	LineElement el4;
	el4.setLabel("element 4");
	el4.setMaterial(Material(21, 0, 0));
	el4.addNode(0, Node(el3.get(1)));
	el4.addNode(1, Node(0.0300));

	Mesh m1d = Mesh(4);

	m1d.addElement(el, 1);
	m1d.addElement(el2, 2);
	m1d.addElement(el3, 3);
	m1d.addElement(el4, 4);

	matrix a = m1d.assemblyStiffMatrix(m1d(1), 1, 1);
	for (int i = 1; i <= LINE; i++) {
		for (int j = 1; j <= LINE; j++) {
			cout << el(i, j) << endl;
		}
	}

	vect v = m1d.assemblyLoadVector(m1d(1), 1, 300000, 1);
	for (int i = 1; i <= LINE; i++) {
		cout << v(i) << endl;
	}

	matrix a1 = m1d.assemblyStiffMatrix(m1d(2), 1, 1);
	for (int i = 1; i <= LINE; i++) {
		for (int j = 1; j <= LINE; j++) {
			cout << el2(i, j) << endl;
		}
	}

	vect v1 = m1d.assemblyLoadVector(m1d(2), 1, 300000, 1);
	for (int i = 1; i <= LINE; i++) {
		cout << v1(i) << endl;
	}

	matrix a2 = m1d.assemblyStiffMatrix(m1d(3), 1, 1);
	for (int i = 1; i <= LINE; i++) {
		for (int j = 1; j <= LINE; j++) {
			cout << el3(i, j) << endl;
		}
	}

	vect v2 = m1d.assemblyLoadVector(m1d(3), 1, 300000, 1);
	for (int i = 1; i <= LINE; i++) {
		cout << v2(i) << endl;
	}

	matrix a3 = m1d.assemblyStiffMatrix(m1d(4), 1, 1);
	for (int i = 1; i <= LINE; i++) {
		for (int j = 1; j <= LINE; j++) {
			cout << el4(i, j) << endl;
		}
	}

	vect v3 = m1d.assemblyLoadVector(m1d(4), 1, 300000, 1);
	for (int i = 1; i <= LINE; i++) {
		cout << v3(i) << endl;
	}

	int totalNode=5;
	matrix global=m1d.assemblyGlobalMatrix(totalNode);

/*
	for(int i=1;i<=totalNode;i++){
		for(int j=1;j<=totalNode;j++){
			global.set(i,j,0.0);

		}
	}
	global.set(1,1,m1d(1)(1,1));
	global.set(totalNode,totalNode,m1d(4)(2,2));
	for(int i=1;i<totalNode;i++){
		for(int j=1;j<totalNode;j++){
			if(i==j){
				global.set(i,i,m1d(i)(1,1)+m1d(i-1)(2,2));
				global.set(i,j+1,m1d(i)(1,2));
				global.set(i,j-1,m1d(i)(2,1));
				global.set(i-1,j,m1d(i)(1,2));
				global.set(i+1,j,m1d(i)(2,1));
			}else{
				global.set(i,j,0.0);
			}
		}
	}
*/
	cout<<"\n\nglobal matrix:\n";

	for (int i = 1; i <= totalNode; i++) {
			for (int j = 1; j <= totalNode; j++) {
				cout << global(i, j) << endl;
			}
		}


	return 0;

}
